import type { SendCodeType, IPageRequest  } from '@/typings/api';
import request from '@/utils/request';
import type { IUser, IPlayRecord  } from '@/typings/interface';


/**
 * 注册
 */
export function register(data: { phone: string; code: string }) {
  return request<string>('/user/v1/register', { data, method: 'POST' });
}

/**
 * 发送短信
 */
export function sendCode(data: {
  phone: string;
  captcha: string;
  type: SendCodeType;
}) {
  
  return request('/notify/v1/send_code', { data, method: 'POST' });
}


/**
 * 获取用户信息
 */
export function getDetail() {
  return request<IUser>('/user/v1/detail');
}

/**
 * 验证码登录
 */
export function loginWithCode(data: { phone: string; code: string }) {
  return request<string>('/user/v1/login', {
    data,
    method: 'POST',
  });
}

/**
 * 密码登录
 */
export function loginWithPassword(data: { phone: string; password: string }) {
  return request<string>('/user/v1/login', {
    data,
    method: 'POST',
  });
}

/**
 * 更新用户信息
 */
export function updateDetails(data: Partial<IUser>) {
  return request('/user/v1/update', {
    data,
    method: 'POST',
  });
}

/**
 * 修改/忘记密码
 */
export function forgetPassword(data: {
  phone: string;
  code: string;
  password: string;
}) {
  return request('/user/v1/forget', {
    data,
    method: 'POST',
  });
}

// 微信登录
export function loginWithApp(code: string) {
  return request<string>(`/wx_login/v1/app_login?code=${code}`);
}

/**
 * 分页查询播放记录
 */
export function queryPlayRecordPage(data: IPageRequest) {
  return request<IPlayRecord, true>('/user/v1/play_record', {
    data,
    method: 'POST',
  });
}
